<?php

namespace App\Clients\Keruyun;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Model;

class StoreQueryBill extends KeruyunClient
{
    public function __construct(Model $account){
        parent::__construct($account);
        $this->queryData = [
            'group' => 'HSF',
            '@class' => 'com.alsc.saas.gw.client.HsfReq',
            'service' => 'com.alsc.saas.fund.merchant.client.api.FundBillFacade',
            'method' => 'queryBill',
            'version' => '1.0.0',
            'eagleEyeUserData' => new \stdClass(),
            'argTypes' => [
                'com.alsc.saas.fund.merchant.client.request.bill.QueryFundBillRequest'
            ],
            'argValues' => [
                [
                    'bSubjectIdList' => [
                        8002968013
                    ],
                    'status' => [
                        'SETTLED',
                        'WAIT_SETTLE',
                        'REMITTED',
                        'SETTLE_ING'
                    ],
                    'billStartDate' => 1755359232826,
                    'billEndDate' => 1755359232826,
                    'pageNo' => 1,
                    'pageSize' => 10
                ]
            ],
            'targetClusterName' => 'alibaba-prod',
            'timeout' => 'PT30S',
            'context' => [
                'visitedDevice' => 'WEB'
            ]
        ];
//        var_dump(json_encode($this->queryData));
//        exit();
    }

    public function handleQueryData($queryData)
    {
        $this->queryData["argValues"][0]["bSubjectIdList"] = [$queryData["poId"]];
        $this->queryData["argValues"][0]["billStartDate"] = $queryData["billStartDate"];
        $this->queryData["argValues"][0]["billEndDate"] = $queryData["billEndDate"];
        !empty($queryData["projectIdList"]) and $this->queryData["argValues"][0]["projectIdList"] = $queryData["projectIdList"];
    }


    /**
     * @throws GuzzleException
     */
    public function execute($queryData = []): StoreQueryBill
    {
//        var_dump(json_encode($queryData));
//        exit();
        return $this->post("https://saas.keruyun.com/saas-gw/secure/v2/req?hsfApi=queryBill",$queryData);
    }
}
